// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

// ****************************************************************************
//  File: IntegralCurveViewerEnginePluginInfo.C
// ****************************************************************************

#include <IntegralCurvePluginInfo.h>
#include <IntegralCurveAttributes.h>

//
// Storage for static data elements.
//
IntegralCurveAttributes *IntegralCurveViewerEnginePluginInfo::clientAtts = NULL;
IntegralCurveAttributes *IntegralCurveViewerEnginePluginInfo::defaultAtts = NULL;

// ****************************************************************************
//  Method:  IntegralCurveViewerEnginePluginInfo::InitializeGlobalObjects
//
//  Purpose:
//    Initialize the operator atts.
//
//  Programmer: generated by xml2info
//  Creation:   omitted
//
// ****************************************************************************
void
IntegralCurveViewerEnginePluginInfo::InitializeGlobalObjects()
{
    if (IntegralCurveViewerEnginePluginInfo::clientAtts == NULL)
    {
        IntegralCurveViewerEnginePluginInfo::clientAtts  = new IntegralCurveAttributes;
        IntegralCurveViewerEnginePluginInfo::defaultAtts = new IntegralCurveAttributes;
    }
}

// ****************************************************************************
//  Method: IntegralCurveViewerEnginePluginInfo::GetClientAtts
//
//  Purpose:
//    Return a pointer to the viewer client attributes.
//
//  Returns:    A pointer to the viewer client attributes.
//
//  Programmer: generated by xml2info
//  Creation:   omitted
//
// ****************************************************************************

AttributeSubject *
IntegralCurveViewerEnginePluginInfo::GetClientAtts()
{
    return clientAtts;
}

// ****************************************************************************
//  Method: IntegralCurveViewerEnginePluginInfo::GetDefaultAtts
//
//  Purpose:
//    Return a pointer to the viewer default attributes.
//
//  Returns:    A pointer to the viewer default attributes.
//
//  Programmer: generated by xml2info
//  Creation:   omitted
//
// ****************************************************************************

AttributeSubject *
IntegralCurveViewerEnginePluginInfo::GetDefaultAtts()
{
    return defaultAtts;
}

// ****************************************************************************
//  Method: IntegralCurveViewerEnginePluginInfo::SetClientAtts
//
//  Purpose:
//    Set the viewer client attributes.
//
//  Arguments:
//    atts      A pointer to the new client attributes.
//
//  Programmer: generated by xml2info
//  Creation:   omitted
//
// ****************************************************************************

void
IntegralCurveViewerEnginePluginInfo::SetClientAtts(AttributeSubject *atts)
{
    *clientAtts = *(IntegralCurveAttributes *)atts;
    clientAtts->Notify();
}

// ****************************************************************************
//  Method: IntegralCurveViewerEnginePluginInfo::GetClientAtts
//
//  Purpose:
//    Get the viewer client attributes.
//
//  Arguments:
//    atts      A pointer to return the client default attributes in.
//
//  Programmer: generated by xml2info
//  Creation:   omitted
//
// ****************************************************************************

void
IntegralCurveViewerEnginePluginInfo::GetClientAtts(AttributeSubject *atts)
{
    *(IntegralCurveAttributes *)atts = *clientAtts;
}

// ****************************************************************************
//  Method: IntegralCurveViewerEnginePluginInfo::InitializeOperatorAtts
//
//  Purpose:
//    Initialize the operator attributes to the default attributes.
//
//  Arguments:
//    atts        The attribute subject to initialize.
//    plot        The viewer plot that owns the operator.
//    fromDefault True to initialize the attributes from the defaults. False
//                to initialize from the current attributes.
//
//  Programmer: generated by xml2info
//  Creation:   omitted
//
// ****************************************************************************

void
IntegralCurveViewerEnginePluginInfo::InitializeOperatorAtts(AttributeSubject *atts,
                                              const avtPlotMetaData &plot,
                                              const bool fromDefault)
{
    if (fromDefault)
        *(IntegralCurveAttributes*)atts = *defaultAtts;
    else
        *(IntegralCurveAttributes*)atts = *clientAtts;

    UpdateOperatorAtts(atts, plot);
}

// ****************************************************************************
//  Method: IntegralCurveViewerEnginePluginInfo::UpdateOperatorAtts
//
//  Purpose:
//    Update the operator attributes when using operator expressions.
//
//  Arguments:
//    atts        The attribute subject to update.
//    plot        The viewer plot that owns the operator.
//
//  Programmer: generated by xml2info
//  Creation:   omitted
//
// ****************************************************************************

void
IntegralCurveViewerEnginePluginInfo::UpdateOperatorAtts(AttributeSubject *atts, const avtPlotMetaData &plot)
{
}

// ****************************************************************************
//  Method: IntegralCurveViewerEnginePluginInfo::GetOperatorVarDescription
//
//  Purpose:
//    Return the operator variable description.
//
//  Arguments:
//    atts        The attribute subject to initialize.
//    plot        The viewer plot that owns the operator.
//
//  Programmer: Allen Sanderson
//  Creation:   19 August 2013
//
// ****************************************************************************

#include <avtPlotMetaData.h>
#include <cstring>
std::string
IntegralCurveViewerEnginePluginInfo::GetOperatorVarDescription(AttributeSubject *atts,
                                                               const avtPlotMetaData &plot)
{
    IntegralCurveAttributes *atts_in = (IntegralCurveAttributes *)atts;

    const char *typeString[14] =
      { "None", "Random", "Seed Point ID", "Speed", "Vorticity", "Arc Length",
         "Absolute Time", "Relative Time",
         "Ave. dist. from seed", "Correlation Distance", "Closed Curve",
         "Difference", "Variable", "VariableAtSeed" };

    std::string var = plot.GetVariableName();

    if( strncmp(var.c_str(), "operators/IntegralCurve/",
                strlen("operators/IntegralCurve/")) == 0)
    {
      std::string justTheVar = var.substr(strlen("operators/IntegralCurve/"));

      var = justTheVar;
    }

    else if( strncmp(var.c_str(), "operators/LCS/",
                     strlen("operators/LCS/")) == 0)
    {
      std::string justTheVar = var.substr(strlen("operators/LCS/"));

      var = justTheVar;
    }

    var += std::string(" - ") +
        std::string(typeString[atts_in->GetDataValue()]);

    if( atts_in->GetDataValue() == IntegralCurveAttributes::Variable ||
        atts_in->GetDataValue() == IntegralCurveAttributes::VariableAtSeed )
    {
        var += std::string(": ") + atts_in->GetDataVariable();
    }

    return var;
}

// ****************************************************************************
//  Method: IntegralCurveViewerEnginePluginInfo::GetMenuName
//
//  Purpose:
//    Return a pointer to the name to use in the viewer menus.
//
//  Returns:    A pointer to the name to use in the viewer menus.
//
//  Programmer: generated by xml2info
//  Creation:   omitted
//
// ****************************************************************************

const char *
IntegralCurveViewerEnginePluginInfo::GetMenuName() const
{
    return "IntegralCurve";
}

